package com.xxpn.controller.client;

import org.json.simple.JSONObject;

import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class ClientSend implements Runnable{
    private Socket socket;
    private ObjectOutputStream oos;
    private int myid;

    public ClientSend(Socket socket, ObjectOutputStream oos,int myid ){
        this.socket = socket;
        this.oos = oos;
        this.myid=myid;
    }

    @Override
    public void run() {
        try {
            Scanner scanner = new Scanner(System.in);
            while (true){
                System.out.println("请输入你要发送的用户：");
                String yid = scanner.nextLine();

                System.out.println("请输入你要发送的信息：");
                String string = scanner.nextLine();

                JSONObject object = new JSONObject();
                object.put("myid",myid);
                object.put("youid",yid);
                object.put("msg",string);
                object.put("type","talk");
                oos.writeObject(object);
                oos.flush();
            }
        }catch (Exception e){
            e.printStackTrace();
            try {
                socket.close();
                Client.connection_state = false;
                Client.reconnect();
            }catch (Exception ee){
                ee.printStackTrace();
            }
        }
    }
}